package com.xiaoying.server.publish.task;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import redis.clients.jedis.Jedis;

import com.xiaoying.server.publish.entity.FileInfo;
import com.xiaoying.server.publish.entity.UploadResult;
import com.xiaoying.server.publish.upload.UploadFile;
import com.xiaoying.server.publish.utils.RedisUtil;


/**
 * 异步Redis备份队列处理
 * @author ZJD
 *
 */
public class BackupUploadInfoDealTask implements Runnable {
	private static Log log = LogFactory.getFactory().getInstance(BackupUploadInfoDealTask.class);
	
	private UploadResult uploadResult;
	private FileInfo fileInfo;
	private Jedis redis;
	
	// mini constructor
	public BackupUploadInfoDealTask(UploadResult uploadResult){
		this.uploadResult=uploadResult;
	}
	
	// full constructor
	public BackupUploadInfoDealTask(FileInfo fileInfo,UploadResult uploadResult){
		this.fileInfo = fileInfo;
		this.uploadResult = uploadResult;
	}
	

	@Override
	public void run() {
		// 获取处理备份的redis客户端
		redis = RedisUtil.getBackupRedisInstance();		
		String key = RedisUtil.PREFIX_XY_BACKUP_UPLOAD_FILEINFO+
					uploadResult.getFileName()+"_"+uploadResult.getUploadDt();
		if(uploadResult!=null){
			redis.del(key);
			log.debug(uploadResult.getId()+" Redis上传备份消息删除成功!!!");
		}else{
			log.error(uploadResult.getId()+" Redis上传备份消息删除失败!!!");
		}
	}

}
